package com.appkubes.fintech.restful.application.user.service.impl;

import com.appkubes.fintech.core.po.FintechUserJob;
import com.appkubes.fintech.restful.application.user.dao.UserJobDao;
import com.appkubes.fintech.restful.application.user.entity.vo.UserJobVO;
import com.appkubes.fintech.restful.application.user.domain.UserCertificateDomain;
import com.appkubes.fintech.restful.application.user.service.UserJobService;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户工作信息表 服务实现类
 * </p>
 *
 * @author rongjie
 * @since 2019-12-26
 */
@Service
@Data
public class UserJobServiceImpl implements UserJobService {
    @Autowired
    UserJobDao userJobDao;
    @Resource
    UserCertificateDomain certificateService;


    @Override
    public Integer jobCertificate(UserJobVO userJobVO) {

        FintechUserJob userJob = userJobDao.selectByPrimaryKey(userJobVO.getUserKey());
        if (userJob == null) {
            //补偿机制
            userJob = new FintechUserJob();
            BeanUtils.copyProperties(userJobVO, userJob);
            userJobDao.insertSelective(userJob);
        }
        BeanUtils.copyProperties(userJobVO, userJob);
        Integer effectRow = userJobDao.updateByPrimaryKey(userJob);
        effectRow += certificateService.updateJobCertificate(userJobVO.getUserKey(), 1);
        return effectRow;
    }
}
